package com.zwr.sheller.customer.controller;

import com.zwr.sheller.core.common.JsonResult;
import com.zwr.sheller.core.common.WQQBusinessException;
import com.zwr.sheller.core.pojo.Goods;
import com.zwr.sheller.core.pojo.Store;
import com.zwr.sheller.core.util.ThreadLocalUtil;
import com.zwr.sheller.customer.Service.StoreShellerIndexService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @Author: 18032
 * @Date: 16:14 2022/1/6
 */
@RestController
@RequestMapping("/shellerStore")
@Api(tags = "剥壳者商城")
public class ShellerStoreController {

    @Autowired
    StoreShellerIndexService storeShellerIndexService;

    @PostMapping("/storeIndex")
    @ApiOperation(value = "剥壳者商城首页")
    @ApiImplicitParam(name = "storeId",value = "店铺id",dataType = "Long")
    public Map<String, Object> selectFruitByType(Long storeId) throws WQQBusinessException {
        Object object = ThreadLocalUtil.getObject();
        System.out.println("user++++++:"+object);

        List<Map<String, Object>> list = storeShellerIndexService.indexData(storeId);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setField("data",list);
        return jsonResult.getMap();
    }

    @PostMapping("/attention")
    @ApiOperation(value = "剥壳者商城:点击关注")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "attention",value = "true是关注成功",dataType = "Boolean"),
            @ApiImplicitParam(name = "storeId",value = "商铺id",dataType = "Long")
    })
    public Map<String, Object> attention(Boolean attention,Long storeId) {
        JsonResult jsonResult = new JsonResult();
        jsonResult.setField("msg","关注成功");
        return jsonResult.getMap();
    }

    @PostMapping("/allGoods")
    @ApiOperation(value = "剥壳者商城:点击全部商品显示")
    @ApiImplicitParam(name = "storeId",value = "商铺id",dataType = "Long")
    public Map<String, Object> allGoods(Long storeId) throws WQQBusinessException {
        List<Goods> goods = storeShellerIndexService.selectAllShellerGoods(storeId);

        JsonResult jsonResult = new JsonResult();
        jsonResult.setField("msg","查询成功");
        jsonResult.setField("data",goods);
        return jsonResult.getMap();
    }

    @PostMapping("/selectBySort")
    @ApiOperation("店铺商品点击,选择按照最新/折扣/销量/价格/")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "storeId",value = "商铺id",dataType = "Long"),
            @ApiImplicitParam(name = "choose",value = "选择:0.最新上架 1.最高折扣 2.销量 3.价格",dataType = "Integer"),
    })
    private Map<String, Object> selectBySort(Long storeId,Integer choose) throws WQQBusinessException {
        List<Map<String, Object>> goodsList = storeShellerIndexService.selectNewOrSaleGoods(storeId, choose);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setField("msg","查询成功");
        jsonResult.setField("data",goodsList);
        return jsonResult.getMap();
    }

    @PostMapping("/selectByOption")
    @ApiOperation("店铺商品点击筛选,")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "storeId",value = "商铺id",dataType = "Long"),
            @ApiImplicitParam(name = "choose",value = "choose为0,热卖,choose为1,新品,choose为2,推荐",dataType = "Integer"),
            @ApiImplicitParam(name = "lowPrice",value = "低价格",dataType = "Double"),
            @ApiImplicitParam(name = "highPrice",value = "低价格",dataType = "Double")

    })
    private Map<String, Object> selectByOptions(Long storeId,Integer choose,Double lowPrice,Double highPrice) throws WQQBusinessException {
        List<Map<String, Object>> list = storeShellerIndexService.selectByOption(storeId, choose, lowPrice, highPrice);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setField("msg","查询成功");
        jsonResult.setField("data",list);
        return jsonResult.getMap();
    }


    @PostMapping("/allTypes")
    @ApiOperation(value = "剥壳者商城:点击商品分类")
    @ApiImplicitParam(name = "storeId",value = "商铺id",dataType = "Long")
    public Map<String, Object> allTypes(Long storeId) {

        JsonResult jsonResult = new JsonResult();
        jsonResult.setField("data","这是假数据");
        return jsonResult.getMap();
    }

    @PostMapping("/introduceStore")
    @ApiOperation(value = "剥壳者商城:店铺介绍")
    @ApiImplicitParam(name = "storeId",value = "商铺id",dataType = "Long")
    public Map<String, Object> introduceStore(Long storeId) throws WQQBusinessException {
        Map<String, Object> map = storeShellerIndexService.introduceStore(storeId);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setField("data",map);
        return jsonResult.getMap();
    }


    @PostMapping("/selectOneSort")
    @ApiOperation(value = "剥壳者点击全部分类出现一级分类")
    @ApiImplicitParam(name = "storeId",value = "商铺id",dataType = "Long")
    public Map<String, Object> selectOneSort(Long storeId) throws WQQBusinessException {
        List<Map<String, Object>> list = storeShellerIndexService.oneSort(storeId);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setField("data",list);
        return jsonResult.getMap();
    }


    @PostMapping("/twoAndThreeSort")
    @ApiOperation(value = "剥壳者点击一级分类出现二级三级分类")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "storeId",value = "商铺id",dataType = "Long"),
            @ApiImplicitParam(name = "itemId",value = "分类id",dataType = "Long"),
    })
    public Map<String, Object> selectTwoAndThreeSort(Long storeId,Long itemId) throws WQQBusinessException {
        List<Map<String, Object>> list = storeShellerIndexService.twoAndThreeSort(storeId,itemId);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setField("data",list);
        return jsonResult.getMap();
    }


    
}
